{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d0da7b7f-0c31-435a-b1fa-df40456376e9",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'DataFrame' object has no attribute 'append'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[1], line 17\u001b[0m\n\u001b[0;32m     15\u001b[0m \u001b[38;5;66;03m# (3) 增加一位员工收入信息\u001b[39;00m\n\u001b[0;32m     16\u001b[0m new_employee \u001b[38;5;241m=\u001b[39m {\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m姓名\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m赵一平\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m性别\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m男\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m年龄\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;241m34\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m月工资收入\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;241m7000\u001b[39m}\n\u001b[1;32m---> 17\u001b[0m df \u001b[38;5;241m=\u001b[39m df\u001b[38;5;241m.\u001b[39mappend(new_employee, ignore_index\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m     19\u001b[0m \u001b[38;5;66;03m# (4) 修改员工姓名为“赵一平”的月工资收入\u001b[39;00m\n\u001b[0;32m     20\u001b[0m df\u001b[38;5;241m.\u001b[39mloc[df[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m姓名\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m赵一平\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m月工资收入\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m8000\u001b[39m\n",
      "File \u001b[1;32mC:\\Anaconda\\Lib\\site-packages\\pandas\\core\\generic.py:6299\u001b[0m, in \u001b[0;36mNDFrame.__getattr__\u001b[1;34m(self, name)\u001b[0m\n\u001b[0;32m   6292\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\n\u001b[0;32m   6293\u001b[0m     name \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_internal_names_set\n\u001b[0;32m   6294\u001b[0m     \u001b[38;5;129;01mand\u001b[39;00m name \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_metadata\n\u001b[0;32m   6295\u001b[0m     \u001b[38;5;129;01mand\u001b[39;00m name \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_accessors\n\u001b[0;32m   6296\u001b[0m     \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_info_axis\u001b[38;5;241m.\u001b[39m_can_hold_identifiers_and_holds_name(name)\n\u001b[0;32m   6297\u001b[0m ):\n\u001b[0;32m   6298\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m[name]\n\u001b[1;32m-> 6299\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mobject\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__getattribute__\u001b[39m(\u001b[38;5;28mself\u001b[39m, name)\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'append'"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# (1) 创建DataFrame\n",
    "data = {\n",
    "    '姓名': ['张三', '李四', '王五', '赵六', '孙七'],\n",
    "    '性别': ['男', '女', '男', '女', '男'],\n",
    "    '年龄': [28, 35, 40, 30, 24],\n",
    "    '月工资收入': [5000, 6200, 7800, 5800, 6500]\n",
    "}\n",
    "df = pd.DataFrame(data)\n",
    "\n",
    "# (2) 选择DataFrame中月工资收入这列数据\n",
    "salary_column = df['月工资收入']\n",
    "\n",
    "# (3) 增加一位员工收入信息\n",
    "new_employee = {'姓名': '赵一平', '性别': '男', '年龄': 34, '月工资收入': 7000}\n",
    "df = df.append(new_employee, ignore_index=True)\n",
    "\n",
    "# (4) 修改员工姓名为“赵一平”的月工资收入\n",
    "df.loc[df['姓名'] == '赵一平', '月工资收入'] = 8000\n",
    "\n",
    "# (5) 删除第2位员工的数据\n",
    "df = df.drop(df.index[1])\n",
    "\n",
    "# (6) 筛选出月工资收入大于6000元的员工的数据\n",
    "high_salary_employees = df[df['月工资收入'] > 6000]\n",
    "\n",
    "# 打印结果\n",
    "print(\"原始DataFrame:\")\n",
    "print(df)\n",
    "print(\"\\n月工资收入列数据:\")\n",
    "print(salary_column)\n",
    "print(\"\\n修改后的DataFrame:\")\n",
    "print(df)\n",
    "print(\"\\n月工资收入大于6000元的员工数据:\")\n",
    "print(high_salary_employees)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6daf2c4d-b6ce-434c-8aee-94b5fa737fc1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pandas in c:\\anaconda\\lib\\site-packages (2.2.3)\n",
      "Requirement already satisfied: numpy>=1.26.0 in c:\\anaconda\\lib\\site-packages (from pandas) (1.26.4)\n",
      "Requirement already satisfied: python-dateutil>=2.8.2 in c:\\anaconda\\lib\\site-packages (from pandas) (2.9.0.post0)\n",
      "Requirement already satisfied: pytz>=2020.1 in c:\\anaconda\\lib\\site-packages (from pandas) (2024.1)\n",
      "Requirement already satisfied: tzdata>=2022.7 in c:\\anaconda\\lib\\site-packages (from pandas) (2023.3)\n",
      "Requirement already satisfied: six>=1.5 in c:\\anaconda\\lib\\site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b129804c-0a94-49a4-af2e-2a5b82253c1a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "22564f8f-994f-4d4d-9dd2-f4e6ba145002",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# (1) 创建DataFrame\n",
    "data = {\n",
    "    '姓名': ['张三', '李四', '王五', '赵六', '孙七'],\n",
    "    '性别': ['男', '女', '男', '女', '男'],\n",
    "    '年龄': [28, 35, 40, 30, 24],\n",
    "    '月工资收入': [5000, 6200, 7800, 5800, 6500]\n",
    "}\n",
    "df = pd.DataFrame(data)\n",
    "\n",
    "# (2) 选择DataFrame中月工资收入这列数据\n",
    "salary_column = df['月工资收入']\n",
    "\n",
    "# (3) 增加一位员工收入信息\n",
    "new_employee = pd.DataFrame({'姓名': ['赵一平'], '性别': ['男'], '年龄': [34], '月工资收入': [7000]})\n",
    "df = pd.concat([df, new_employee], ignore_index=True)\n",
    "\n",
    "# (4) 修改员工姓名为“赵一平”的月工资收入\n",
    "df.loc[df['姓名'] == '赵一平', '月工资收入'] = 8000\n",
    "\n",
    "# (5) 删除第2位员工的数据\n",
    "df = df.drop(df.index[1])\n",
    "\n",
    "# (6) 筛选出月工资收入大于6000元的员工的数据\n",
    "high_salary_employees = df[df['月工资收入'] > 6000]\n",
    "\n",
    "# 打印结果\n",
    "print(\"原始DataFrame:\")\n",
    "print(df)\n",
    "print(\"\\n月工资收入列数据:\")\n",
    "print(salary_column)\n",
    "print(\"\\n修改后的DataFrame:\")\n",
    "print(df)\n",
    "print(\"\\n月工资收入大于6000元的员工数据:\")\n",
    "print(high_salary_employees)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
